//#include "StdAfx.h"
#include "base_ini.h"

CBaseIni::CBaseIni(void)
{
}
CBaseIni::CBaseIni( cstr_t lpszFileName )
{
	m_strFileName = lpszFileName;
}
CBaseIni::~CBaseIni(void)
{
}
void   CBaseIni::Ini( cstr_t lpszFileName )
{
	m_strFileName = lpszFileName;
}
bool   CBaseIni::WriteStr( cstr_t lpszAppName, cstr_t lpszKeyName, cstr_t lpszString/*, cstr_t lpszFileName = NULL*/ )
{
	return WritePrivateProfileString( lpszAppName, lpszKeyName, lpszString, m_strFileName.c_str() ) == TRUE;
}
bool CBaseIni::WriteStruct( cstr_t lpszAppName, cstr_t lpszKeyName, void * pStruct, uint32 nSizeStruct )
{
	return WritePrivateProfileStruct( lpszAppName, lpszKeyName, pStruct, nSizeStruct, m_strFileName.c_str() ) == TRUE;
}
bool   CBaseIni::WriteInt( cstr_t lpszAppName, cstr_t lpszKeyName, int nValue )
{
	char_t buf[32];
	_stprintf_s( buf, 32, _T("%d"), nValue );
	return WritePrivateProfileString( lpszAppName, lpszKeyName, buf, m_strFileName.c_str() ) == TRUE;
}
uint32 CBaseIni::ReadStr( cstr_t lpszAppName, cstr_t lpszKeyName, cstr_t lpDefault, string_t & strValue/*, cstr_t lpszFileName = NULL*/ )
{
	char_t buf[256];
	uint32 nSize =  GetPrivateProfileString( lpszAppName, lpszKeyName, lpDefault, buf, 256, m_strFileName.c_str() );
	if( nSize > 0 )
	{
		strValue = buf;
	}
	return nSize;
}
int32  CBaseIni::ReadInt( cstr_t lpszAppName, cstr_t lpszKeyName, int32 nDefault/*, cstr_t lpszFileName = NULL*/ )
{
	return GetPrivateProfileInt( lpszAppName, lpszKeyName, nDefault, m_strFileName.c_str() );
}
int64  CBaseIni::ReadInt64( cstr_t lpszAppName, cstr_t lpszkeyName, int64 nDefault )
{
	char_t buf[48];
	int nSize = GetPrivateProfileString( lpszAppName, lpszkeyName, _T("0"), buf, 48, m_strFileName.c_str() );
	return _tstoi64( buf );
}
bool CBaseIni::ReadStruct( cstr_t lpszAppName, cstr_t lpszKeyName, void * pStruct, uint32 nSizeStruct )
{
	return GetPrivateProfileStruct( lpszAppName, lpszKeyName, pStruct, nSizeStruct, m_strFileName.c_str() )==TRUE;
}
int  CBaseIni::GetAllSectionNames( char_t * pBuf, int nBuflen )
{
	return GetPrivateProfileSectionNames( pBuf, nBuflen, m_strFileName.c_str() );
}